var _origServerURL='';
var _origFolder='';
var _origUid='';
var _origPwd='';
var _origbbcompat='';
var _origoutlookcompat='';
var _origuseheader='';
var _origesc='';

function showHelp()
{
  var cl = new java.net.URLClassLoader(_toJavaUrlArray(['file:///C:/Users/Michael/Desktop/Development Projects/ThunderNote/3.0/src/components/thundernote.jar']));
  alert(cl);
  var loadedClass = cl.loadClass("thundernote.ThunderNote");
  alert(loadedClass);
  var classInst = loadedClass.newInstance();
  alert(classInst);
  alert(classInst.getVersion());
}

function  _toJavaUrlArray(a) 
{  
  var urlArray = java.lang.reflect.Array.newInstance(java.net.URL, a.length);  
  for (var i = 0; i < a.length; i++) {  
   var url = a[i];  
   java.lang.reflect.Array.set(  
    urlArray,  
    i,  
    (typeof url == "string") ? new java.net.URL(url) : url  
   );  
  }  
  return urlArray;  
} 

function applyConfig()
{
  var cfg=readConfig();
  var children=cfg.documentElement.childNodes;
  
  for(var x=0;x<children.length;x++)
  {
    if(children[x].nodeName=='Sync')
      applySyncConfig(children[x]);
  }
}

function applySyncConfig(node)
{
  var children=node.childNodes;
  var serverurl='';
  var foldername='';
  var uid='';
  var pwd='';
  var bbcompat='true';
  var outlookcompat='false';
  var useheader='true';
  var esc='false';

  var statusLine=document.getElementById('statuslabel');
  var urlLine=document.getElementById('syncmlserver');
  var folderLine=document.getElementById('notesfolder');
  var uidLine=document.getElementById('uid');
  var pwdLine=document.getElementById('pwd');
  var bbcompatcb=document.getElementById('bbcompat');
  var outlookcompatcb=document.getElementById('outlookcompat');
  var useheadercb=document.getElementById('useheader');
  var esccb=document.getElementById('esc');
  
  statusLine.value="Reading config...";
  
  for(var x=0;x<children.length;x++)
  {
    if(children[x].nodeName=='SyncMLServer')
      serverurl=getXMLNodeValue(children[x]);
    if(children[x].nodeName=='RemoteNotesFolder')
      foldername=getXMLNodeValue(children[x]);
    if(children[x].nodeName=='UserID')
      uid=getXMLNodeValue(children[x]);
    if(children[x].nodeName=='Password')
      pwd=getXMLNodeValue(children[x]);
    if(children[x].nodeName=='EscapeCSV')
      esc=getXMLNodeValue(children[x]);
    if(children[x].nodeName=='UseHeader')
      useheader=getXMLNodeValue(children[x]);
    if(children[x].nodeName=='BBCompat')
      bbcompat=getXMLNodeValue(children[x]);
    if(children[x].nodeName=='OutlookCompat')
      outlookcompat=getXMLNodeValue(children[x]);
  }

  if(serverurl==null) serverurl='';
  if(foldername==null) foldername='';
  if(uid==null) uid='';
  if(pwd==null) pwd='';

  urlLine.value=serverurl;
  _origServerURL=serverurl;
  folderLine.value=foldername;
  _origFolder=foldername;
  uidLine.value=uid;
  _origUid=uid;
  pwdLine.value=pwd;
  _origPwd=pwd;

  if(bbcompat=='true')
    bbcompatcb.checked=true;
  else
    bbcompatcb.checked=false;
  _origbbcompat=bbcompat;

  if(outlookcompat=='true')
    outlookcompatcb.checked=true;
  else
    outlookcompatcb.checked=false;
  _origoutlookcompat=outlookcompat;

  if(useheader=='true')
    useheadercb.checked=true;
  else
    useheadercb.checked=false;
  _origuseheader=useheader;
  
  if(esc=='true')
    esccb.checked=true;
  else
    esccb.checked=false;
  _origesc=esc;

  statusLine.value="N/A";
}

function resaveConfig()
{
  var serverurl='';
  var foldername='';
  var uid='';
  var pwd='';
  var bbcompat='true';
  var outlookcompat='false';
  var useheader='true';
  var esc='false';
  var statusLine=document.getElementById('statuslabel');
  var urlLine=document.getElementById('syncmlserver');
  var folderLine=document.getElementById('notesfolder');
  var uidLine=document.getElementById('uid');
  var pwdLine=document.getElementById('pwd');
  var bbcompatcb=document.getElementById('bbcompat');
  var outlookcompatcb=document.getElementById('outlookcompat');
  var useheadercb=document.getElementById('useheader');
  var esccb=document.getElementById('esc');
  var changed=false;

  statusLine.value="Checking for changes...";

  serverurl=urlLine.value;
  foldername=folderLine.value;
  uid=uidLine.value;
  pwd=pwdLine.value;
  
  if(bbcompatcb.checked)
    bbcompat='true';
  else
    bbcompat='false';
    
  if(outlookcompatcb.checked)
    outlookcompat='true';
  else
    outlookcompat='false';

  if(useheadercb.checked)
    useheader='true';
  else
    useheader='false';
  
  if(esccb.checked)
    esc='true';
  else
    esc='false';

  if(serverurl==null) serverurl='';
  if(foldername==null) foldername='';
  if(uid==null) uid='';
  if(pwd==null) pwd='';
  
  serverurl=serverurl.trim();
  foldername=foldername.trim();
  uid=uid.trim();
  pwd=pwd.trim();
  _origServerURL=_origServerURL.trim();
  _origFolder=_origFolder.trim();
  _origUid=_origUid.trim();
  _origPwd=_origPwd.trim();

  if(serverurl!=_origServerURL)
    changed=true;
  if(foldername!=_origFolder)
    changed=true;
  if(uid!=_origUid)
    changed=true;
  if(pwd!=_origPwd)
    changed=true;

  if(bbcompat!=_origbbcompat)
    changed=true;
  if(outlookcompat!=_origoutlookcompat)
    changed=true;
  if(useheader!=_origuseheader)
    changed=true;
  if(esc!=_origesc)
    changed=true;

  if(changed)
  {
    statusLine.value="Saving configuration...";

    var dom = readConfig();
    var escTextNode=dom.createTextNode(esc);
    var useheaderTextNode=dom.createTextNode(useheader);
    var bbcompatTextNode=dom.createTextNode(bbcompat);
    var outlookcompatTextNode=dom.createTextNode(outlookcompat);
    var serverurlTextNode=dom.createTextNode(serverurl);
    var foldernameTextNode=dom.createTextNode(foldername);
    var contactsfoldernameTextNode=dom.createTextNode('Card');
    var calfoldernameTextNode=dom.createTextNode('Event');
    var uidTextNode=dom.createTextNode(uid);
    var pwdTextNode=dom.createTextNode(pwd);
    var e1=dom.createElement("Sync");
    
    var c1=dom.createElement("EscapeCSV");
    c1.appendChild(escTextNode);
    
    var c2=dom.createElement("UseHeader");
    c2.appendChild(useheaderTextNode);

    var c3=dom.createElement("BBCompat");
    c3.appendChild(bbcompatTextNode);

    var c4=dom.createElement("OutlookCompat");
    c4.appendChild(outlookcompatTextNode);

    var c5=dom.createElement("SyncMLServer");
    c5.appendChild(serverurlTextNode);

    var c6=dom.createElement("RemoteNotesFolder");
    c6.appendChild(foldernameTextNode);

    var c7=dom.createElement("RemoteContactsFolder");
    c7.appendChild(contactsfoldernameTextNode);

    var c8=dom.createElement("RemoteCalendarFolder");
    c8.appendChild(calfoldernameTextNode);

    var c9=dom.createElement("UserID");
    c9.appendChild(uidTextNode);

    var c10=dom.createElement("Password");
    c10.appendChild(pwdTextNode);

    e1.appendChild(c1);
    e1.appendChild(c2);
    e1.appendChild(c3);
    e1.appendChild(c4);
    e1.appendChild(c5);
    e1.appendChild(c6);
    e1.appendChild(c7);
    e1.appendChild(c8);
    e1.appendChild(c9);
    e1.appendChild(c10);

    var children=dom.documentElement.childNodes;
    for(var x=0;x<children.length;x++)
    {
      if(children[x].nodeName=='Sync')
        dom.documentElement.replaceChild(e1,children[x]);
    }
    
    writeConfig(dom);
  }

  statusLine.value="N/A";
}

function importNotes()
{
  var statusLine=document.getElementById('statuslabel');
  var nsIFilePicker = Components.interfaces.nsIFilePicker;
  var fileBox;
  var fileObj;
  var fileChooser;
  var fileName;
  var xmlFile=false;
  var csvFile=false;
  var fileContents='';
  var bbcompatcb=document.getElementById('bbcompat');
  var outlookcompatcb=document.getElementById('outlookcompat');
  var useheadercb=document.getElementById('useheader');
  var esccb=document.getElementById('esc');
  var bbcompat;
  var outlookcompat;
  var useheader;
  var esc;

  bbcompat=bbcompatcb.checked;
  outlookcompat=outlookcompatcb.checked;
  useheader=useheadercb.checked;
  esc=esccb.checked;

  fileChooser = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
  fileChooser.init(window, "Select a file to import notes from",nsIFilePicker.modeOpen);
  if(bbcompat || outlookcompat)
  {
    fileChooser.appendFilter("CSV Files","*.csv");
    fileChooser.appendFilter("XML Files","*.xml");
  }
  else
  {
    fileChooser.appendFilter("XML Files","*.xml");
    fileChooser.appendFilter("CSV Files","*.csv");
  }
  fileBox = fileChooser.show();

  if(fileBox==nsIFilePicker.returnOK || fileBox==nsIFilePicker.returnReplace)
  {
    fileObj=fileChooser.file;
    fileName=fileObj.path;
    if(fileName.length-fileName.toLowerCase().lastIndexOf(".xml")==4)
      xmlFile=true;
    if(fileName.length-fileName.toLowerCase().lastIndexOf(".csv")==4)
      csvFile=true;

    if(csvFile || xmlFile)
    {
      statusLine.value="Importing Notes...";
      fileContents=FileIO.read(fileObj);
      if(xmlFile)
        importXMLFile(fileContents);
      else
      {
        if(bbcompat)
          importBBFile(fileContents);
        else
        {
          if(outlookcompat)
            importOutlookFile(fileContents);
          else
            importCsvFile(fileContents,useheader,esc);
        }
      }
      statusLine.value="N/A";
    }
    else
      alert('Currently, only XML and CSV files are supported');
  }
}

function importXMLFile(fileContents)
{
  var parser = new DOMParser();
  var dom = parser.parseFromString(fileContents, "text/xml");
  var notecount=0;
  var children;  
  var d=new Date();
  var idx=d.getTime();
  
  children=dom.documentElement.childNodes;
  for(var x=0;x<children.length;x++)
  {
    if(children[x].nodeName=='ThunderNote')
    {
      importThunderNoteNode(children[x],idx+notecount);
      notecount++;
    }
  }
  
  alert(notecount+' Notes imported');
}

function importThunderNoteNode(xmlNode,idx)
{
  var children=xmlNode.childNodes;
  var title='',note='',createdtg='',moddtg='';
  
  for(var x=0;x<children.length;x++)
  {
    if(children[x].nodeName=='Title')
      title=getXMLNodeValue(children[x]);
    if(children[x].nodeName=='Body')
      note=getXMLNodeValue(children[x]);
    if(children[x].nodeName=='CreationDTG')
      createdtg=getXMLNodeValue(children[x]);
    if(children[x].nodeName=='UpdateDTG')
      moddtg=getXMLNodeValue(children[x]);
  }

  title=unescape(title);
  note=unescape(note);
  opener.createNewNote(title,note,idx,-1,'');
}

function importOutlookFile(fileContents)
{
  var stringarray=fileContents.split('\"\r\n');
  var note;
  var stringarray2;
  var note2,title;
  var notecount=0;
  var d=new Date();
  var idx=d.getTime();
  var catat,crat;

  for(var x=0;x<stringarray.length;x++)
  {
    note=stringarray[x];
    note=note.trim();
    if(note!='')
    {
      if(note.indexOf('\"Note Body\",\"Categories\",\"Note Color\",\"Priority\",\"Sensitivity\"')==0)
        note=note.substring(62);
      if(note=='\"Note Body\",\"Categories\",\"Note Color\",\"Priority\",\"Sensitivity')
        note='';
      note=note.trim();
      if(note!='')
      {
        catat=note.indexOf('\",,\"');
        if(catat>-1)
        {
          note=note.substring(0,catat);
          note=note.substring(1);
          note=note.trim();
          crat=note.indexOf('\n');
          if(crat!=-1)
          {
            title=note.substring(0,crat);
            title=title.trim();
            note2=note.substring(crat);
            note2=note2.trim();
            note2='\n'+note2;
          }
          else
          {
            title=note.trim();
            note2='';
          }

          opener.createNewNote(title,note2,idx+notecount,-1,'');
          notecount++;
          
        }
      }
    }
  }

  alert(notecount+' Notes imported');
}

function importBBFile(fileContents)
{
  var stringarray=fileContents.split('\",\r\n');
  var note;
  var stringarray2;
  var note2,title;
  var notecount=0;
  var d=new Date();
  var idx=d.getTime();
  
  for(var x=0;x<stringarray.length;x++)
  {
    note=stringarray[x];
    note=note.trim();
    if(note!='')
    {
      if(note.indexOf('\"Note Title\",\"Note Body\",\"Categories\"')==0)
        note=note.substring(37);
      note=note.trim();
      if(note!='')
      {
        if(note.length-note.lastIndexOf('\",')==2)
          note=note.substring(0,note.length-2);
        stringarray2=note.split('\",\"');
        if(stringarray2.length==2)
        {
          title=stringarray2[0];
          note2=stringarray2[1];
          title=title.trim();
          title=title.substring(1);
          note2=note2.trim();
          note2='\n'+note2;
          
          opener.createNewNote(title,note2,idx+notecount,-1,'');
          notecount++;
        }
      }
    }
  }
  
  alert(notecount+' Notes imported');
}

function importCsvFile(fileContents,useheader,esc)
{
  var stringarray=fileContents.split('\"\r\n');
  var note;
  var stringarray2;
  var note2,title;
  var notecount=0;
  var d=new Date();
  var idx=d.getTime();
  
  for(var x=0;x<stringarray.length;x++)
  {
    note=stringarray[x];
    note=note.trim();
    if(note!='')
    {
      if((useheader && notecount>0) || !useheader)
      {
        if(esc)
        {
          stringarray2=note.split(',');
          if(stringarray2.length==4)
          {
            title=stringarray2[0];
            title=title.substring(0,title.length-1);
            title=title.substring(1);
            title=title.trim();
            note2=stringarray2[1];
            note2=note2.substring(0,note2.length-1);
            note2=note2.substring(1);
            note2=note2.trim();
            title=unescape(title);
            note2=unescape(note2);
            title=title.trim();
            note2=note2.trim();
            note2='\n'+note2;
    
            opener.createNewNote(title,note2,idx+notecount,-1,'');
            notecount++;
          }
        }
        else
        {
          stringarray2=note.split('\",\"');
          if(stringarray2.length==4)
          {
            title=stringarray2[0];
            title=title.substring(1);
            title=title.trim();
            note2=stringarray2[1];
            note2=note2.substring(1);
            note2=note2.trim();
            title=title.trim();
            note2=note2.trim();
            note2='\n'+note2;
    
            opener.createNewNote(title,note2,idx+notecount,-1,'');
            notecount++;
          }
        }
      }
      else
        notecount++;
    }
  }
  
  if(useheader && notecount>0)
    notecount--;
  alert(notecount+' Notes imported');
}

function exportNotes()
{
  var statusLine=document.getElementById('statuslabel');
  var bbcompatcb=document.getElementById('bbcompat');
  var outlookcompatcb=document.getElementById('outlookcompat');
  var useheadercb=document.getElementById('useheader');
  var esccb=document.getElementById('esc');
  var bbcompat;
  var outlookcompat;
  var useheader;
  var esc;

  var nsIFilePicker = Components.interfaces.nsIFilePicker;
  var fileBox;
  var fileObj;
  var fileChooser;
  var fileName;
  var xmlFile=false;
  var csvFile=false;
  var dom,children;
  var notecount=0;
  
  bbcompat=bbcompatcb.checked;
  outlookcompat=outlookcompatcb.checked;
  useheader=useheadercb.checked;
  esc=esccb.checked;

  fileChooser = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
  fileChooser.init(window, "Select a file to export your notes to",nsIFilePicker.modeSave);
  if(bbcompat || outlookcompat)
  {
    fileChooser.appendFilter("CSV Files","*.csv");
    fileChooser.appendFilter("XML Files","*.xml");
  }
  else
  {
    fileChooser.appendFilter("XML Files","*.xml");
    fileChooser.appendFilter("CSV Files","*.csv");
  }
  fileBox = fileChooser.show();
  
  if(fileBox==nsIFilePicker.returnOK || fileBox==nsIFilePicker.returnReplace)
  {
    fileObj=fileChooser.file;
    fileName=fileObj.path;
    if(fileName.length-fileName.toLowerCase().lastIndexOf(".xml")==4)
      xmlFile=true;
    if(fileName.length-fileName.toLowerCase().lastIndexOf(".csv")==4)
      csvFile=true;

    if(csvFile || xmlFile)
    {
      statusLine.value="Exporting Notes...";

      if(xmlFile)
        FileIO.write(fileObj,"<ThunderNotes>\n");
      else
      {
        if(bbcompat)
          FileIO.write(fileObj,"\"Note Title\",\"Note Body\",\"Categories\"\r\n");
        else
        {
          if(outlookcompat)
            FileIO.write(fileObj,"\"Note Body\",\"Categories\",\"Note Color\",\"Priority\",\"Sensitivity\"\r\n");
          else
          {
            if(useheader)
              FileIO.write(fileObj,"\"Title\",\"Body\",\"CreationDTG\",\"UpdateDTG\"\r\n");
            else
              FileIO.write(fileObj,"");
          }
        }
      }
      
      // cycle through all notes
      dom = readThunderNotes();
      children=dom.documentElement.childNodes;
      for(var x=0;x<children.length;x++)
      {
        if(children[x].nodeName=='ThunderNote')
        {
          exportThunderNoteNode(children[x],csvFile,xmlFile,bbcompat,outlookcompat,esc,fileObj);
          notecount++;
        }
      }
      if(xmlFile)
        FileIO.write(fileObj,"</ThunderNotes>",'a');
        
      alert(notecount+' Notes exported');
      statusLine.value="N/A";
    }
    else
      alert('Currently, only XML and CSV files are supported');
  }
}

function exportThunderNoteNode(xmlNode,isCsv,isXml,bbcompat,outlookcompat,esc,theFile)
{
  var children=xmlNode.childNodes;
  var title='',note='',createdtg='',moddtg='';
  
  for(var x=0;x<children.length;x++)
  {
    if(children[x].nodeName=='Title')
      title=getXMLNodeValue(children[x]);
    if(children[x].nodeName=='Body')
      note=getXMLNodeValue(children[x]);
    if(children[x].nodeName=='CreationDTG')
      createdtg=getXMLNodeValue(children[x]);
    if(children[x].nodeName=='UpdateDTG')
      moddtg=getXMLNodeValue(children[x]);
  }

  if(title.indexOf(' ')!=-1)
    title=escape(title);
  if(note.indexOf(' ')!=-1)
    note=escape(note);

  if(isXml)
  {
    FileIO.write(theFile,'  <ThunderNote>\n','a');

    FileIO.write(theFile,'    <Title>','a');
    FileIO.write(theFile,title,'a');
    FileIO.write(theFile,'</Title>\n','a');

    FileIO.write(theFile,'    <Body>','a');
    FileIO.write(theFile,note,'a');
    FileIO.write(theFile,'</Body>\n','a');

    FileIO.write(theFile,'    <CreationDTG>','a');
    FileIO.write(theFile,createdtg,'a');
    FileIO.write(theFile,'</CreationDTG>\n','a');

    FileIO.write(theFile,'    <UpdateDTG>','a');
    FileIO.write(theFile,moddtg,'a');
    FileIO.write(theFile,'</UpdateDTG>\n','a');

    FileIO.write(theFile,'  </ThunderNote>\n','a');
  }
  else
  {
    if(bbcompat)
    {
      title=unescape(title);
      note=unescape(note);
      note=note.replace(/\"/g,'\"\"');
      FileIO.write(theFile,'\"','a');
      FileIO.write(theFile,title,'a');
      FileIO.write(theFile,'\",\"','a');
      FileIO.write(theFile,note,'a');
      FileIO.write(theFile,'\",\r\n','a');
    }
    else
    {
      if(outlookcompat)
      {
        title=unescape(title);
        note=unescape(note);
        note=note.replace(/\"/g,'\"\"');
        FileIO.write(theFile,'\"','a');
        FileIO.write(theFile,title,'a');
        //FileIO.write(theFile,'\n','a');
        FileIO.write(theFile,note,'a');
        FileIO.write(theFile,'\",,\"3\",\"Normal\",\"Normal\"\r\n','a');
      }
      else
      {
        if(!esc)
        {
          title=unescape(title);
          note=unescape(note);
          note=note.replace(/\"/g,'\"\"');
        }
        
        FileIO.write(theFile,'\"','a');
        FileIO.write(theFile,title,'a');
        FileIO.write(theFile,'\",\"','a');
        FileIO.write(theFile,note,'a');
        FileIO.write(theFile,'\",\"','a');
        FileIO.write(theFile,createdtg,'a');
        FileIO.write(theFile,'\",\"','a');
        FileIO.write(theFile,moddtg,'a');
        FileIO.write(theFile,'\"\r\n','a');
      }
    }
  }
}

function clickedBB()
{
  var bbcompatcb=document.getElementById('bbcompat');
  var outlookcompatcb=document.getElementById('outlookcompat');
  var useheadercb=document.getElementById('useheader');
  var esccb=document.getElementById('esc');
  
  if(bbcompatcb.checked)
  {
    // this actually gets called before the change so if we get here, it means we are unchecking the box
  }
  else
  {
    useheadercb.checked=true;
    esccb.checked=false;
    outlookcompatcb.checked=false;
  }
}

function clickedOutlook()
{
  var bbcompatcb=document.getElementById('bbcompat');
  var outlookcompatcb=document.getElementById('outlookcompat');
  var useheadercb=document.getElementById('useheader');
  var esccb=document.getElementById('esc');
  
  if(outlookcompatcb.checked)
  {
    // this actually gets called before the change so if we get here, it means we are unchecking the box
  }
  else
  {
    useheadercb.checked=true;
    esccb.checked=false;
    bbcompatcb.checked=false;
  }
}

function sync()
{
  var paths=new Array();
  var tnjarpath;
  var syncmljar1path;
  var syncmljar2path;
  var syncmljar3path;
  var cl;
  var loadedClass;
  var classInst;
  var statusLine=document.getElementById('statuslabel');
  var urlLine=document.getElementById('syncmlserver');
  var folderLine=document.getElementById('notesfolder');
  var uidLine=document.getElementById('uid');
  var pwdLine=document.getElementById('pwd');

  statusLine.value="Synchronizing changes...";

  serverurl=urlLine.value;
  foldername=folderLine.value;
  uid=uidLine.value;
  pwd=pwdLine.value;
  
  /*
  tnjarpath=getJarFileLocalPath('thundernote.jar');
  tnjarpath=tnjarpath.replace(/\\/g,'/');
  tnjarpath='file:///'+tnjarpath;

  syncmljar1path=getJarFileLocalPath('funambol-j2me-common.jar');
  syncmljar1path=syncmljar1path.replace(/\\/g,'/');
  syncmljar1path='file:///'+syncmljar1path;

  syncmljar2path=getJarFileLocalPath('funambol-j2me-syncml.jar');
  syncmljar2path=syncmljar2path.replace(/\\/g,'/');
  syncmljar2path='file:///'+syncmljar2path;

  syncmljar3path=getJarFileLocalPath('funambol-j2me-mail.jar');
  syncmljar3path=syncmljar3path.replace(/\\/g,'/');
  syncmljar3path='file:///'+syncmljar3path;

  paths[0]=tnjarpath;
  paths[1]=syncmljar1path;
  paths[2]=syncmljar2path;
  paths[3]=syncmljar3path;
  
  cl = new java.net.URLClassLoader(_toJavaUrlArray(paths));
  loadedClass = cl.loadClass("thundernote.ThunderNote");
  classInst = loadedClass.newInstance();
  
  serverurl=urlLine.value;
  foldername=folderLine.value;
  uid=uidLine.value;
  pwd=pwdLine.value;
  
  classInst.setConnectionParameters(serverurl,foldername,'','',uid,pwd);
  
  var request =  new XMLHttpRequest();
  if(request==null) alert('NULL');
  //if(classInst.initializeConnection())
  //{
    alert('ok');
  //}
  //else
  //  alert('An error occured initializing the connection : '+classInst.getLastError());
  */
  alert('SyncML Sync is not implemented in this version of ThunderNote.');
  //statusLine.value="Detecting server version...";
  //var dsServerVersion=__SYNCML.getDSVersion(serverurl);
  //
  //if(dsServerVersion!=null)
  //{
  //  if(dsServerVersion!='')
  //  {
  //    alert(dsServerVersion);
  //  }
  //  else
  //    alert(__SYNCML.getLastError());
  // }
  //else
  //  alert(__SYNCML.getLastError());
    
//   try
//   {
//    alert(__SYNCML.getDSVersion(serverurl));
//    alert(__SYNCML.getLastError());
//   }
//   catch(ee)
//   {
//    alert('aa');
//   } 

  
  
  statusLine.value="N/A";
}
